<?php

/**
 * @Description    角色控制器
 * @Author         songgy <Email:songgy@liuniukeji.com>, zhaojiping@2022/1/20
 * @Copyright      山东艾思软件科技有限公司(https://www.aisisofit.cn)
 * @Date           2019/2/22
 * @CreateBy       VS Code
 */

namespace app\core\controller;

use app\common\controller\CommonController;
use app\core\model\CoreRule;

class RuleController extends CommonController {

    protected $model = null;
    protected $validate = null;

    /**
     * 初始化
     */
    public function initialize() {
        parent::initialize();
        $this->model = new CoreRule();
        $this->validate = new \app\core\validate\CoreRule();
    }

    /**
     * 获取数据列表
     */
    public function lists() {
        $pid = input('pid/d', 0);
        $keyword = input('keyword', '');
        $where = [];
        if ($pid > 0) $where[] = ['pid', '=', $pid];
        if ($keyword != '') $where[] = ['name|title|remark', 'like', "%$keyword%"];
        //p($keyword);
        $data = $this->model->getPageList($where);
        // echo $this->model->getlastsql();
        json_return(1, '数据列表', $data);
    }

    /**
     * 列表形式的所有菜单, 但按分组模式, 含等级
     */
    public function getListsByLevel() {
        $where['is_menu'] = 1; // 是否为菜单, 只查询菜单项
        $result = $this->model->getList();
        $data = $this->model->getListByLevel($result);

        json_return(1, '菜单列表', $data);
    }

    /**
     * 返回树型结构的所有菜单
     */
    public function getRuleTree() {
        $result = $this->model->getList();
        $data = $this->model->getTree($result);

        json_return(1, '菜单列表', $data);
    }
}
